// pages/takeBill/takeBill.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isPrintShow: false,//打印业务
    isCardShow: true,//名片制作
    isScrollShow: true,//条幅制作
    isSlotShow: true,//排版
    isDevise: true,//线上设计
    time: "",
    bizType: [
      { value: '10', name: '打印业务', checked: 'true' },
      { value: '20', name: '名片制作' },
      { value: '40', name: '排版' },
      { value: '30', name: '条幅制作' },
      { value: '50', name: '线上设计' },
    ],
    //打印业务
    colorList: "",//颜色
    sizeList: "",//尺寸
    printTypeList: "",//打印类型
    printPaperTypeList: "",//纸张类型
    bindTypeList: "",//装订方式
    //名片制作
    cardPaperTypeList: "",//纸张
    //条幅制作
    bannerColorList: "",//颜色
    //线上设计
    designTypeList: "",//类型
    //页面参数
    formData: {
      name: "",//姓名
      phone: "",//电话
      wxCompany: "",//单位
      bizType: "",//业务
      //打印业务
      color: "",//颜色
      size: "",//尺寸
      printType: "",//打印类型
      printPaperType: "",//纸张类型
      num_dy: "",//数量
      bindType:"",//装订方式
      bindNum:"",//装订本数
      other_demand_dy: "",//其他要求
      //名片制作
      num_mp:"",//数量
      cardPaperType:"",//纸张
      other_demand_mp: "",//其他要求
      //条幅制作
      length:"",//长度
      bannerColor:"",//颜色
      other_demand_tf: "",//其他要求
      //排版
      other_demand_pb: "",//其他要求
      //线上设计
      designType:"",//类型
      other_demand_xs: "",//其他要求
      expect_date: "",//期望时间
      designer_id: "",//设计师ID
      designer_name: "",//设计师姓名
    },
    rules: [{
      name: 'name',
      rules: {required: true, message: '请输入姓名'},
    },{
      name: 'phone',
      rules: [{required: true, message: '请输入电话'},
      {mobile: true, message: '手机号格式不对'}]
    },{
      name: 'bizType',
      rules: {required: false, message: '业务为必选框'},
    }]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let date = new Date();
    // 时区补偿
    date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
    this.setData({
      //时间赋值
      time: date.toJSON().substr(0, 10),
      //打印业务
      colorList: require('../../utils/staticData.js').colorList,//颜色
      sizeList: require('../../utils/staticData.js').sizeList,//尺寸
      printTypeList: require('../../utils/staticData.js').printTypeList,//打印类型
      printPaperTypeList: require('../../utils/staticData.js').printPaperTypeList,//纸张类型
      bindTypeList: require('../../utils/staticData.js').bindTypeList,//装订方式
      //名片制作
      cardPaperTypeList: require('../../utils/staticData.js').cardPaperTypeList,//纸张
      //条幅制作
      bannerColorList: require('../../utils/staticData.js').bannerColorList,//颜色
      //线上设计
      designTypeList: require('../../utils/staticData.js').designTypeList,//类型
    })
  },
  //业务radio调用方法
  radioChangeBizType: function (e) {
    //打印业务//名片制作//条幅制作//排版
    let isPrintShow,isCardShow,isScrollShow,isSlotShow,isDevise;
    const items = this.data.bizType
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //判断view显示隐藏
    if(e.detail.value == "10"){
      this.isPrintShow = false;
      this.isCardShow = true;
      this.isScrollShow = true;
      this.isSlotShow = true;
      this.isDevise = true;
    }else if(e.detail.value == "20"){
      this.isPrintShow = true;
      this.isCardShow = false;
      this.isScrollShow = true;
      this.isSlotShow = true;
      this.isDevise = true;
    }else if(e.detail.value == "30"){
      this.isPrintShow = true;
      this.isCardShow = true;
      this.isScrollShow = false;
      this.isSlotShow = true;
      this.isDevise = true;
    }else if(e.detail.value == "40"){
      this.isPrintShow = true;
      this.isCardShow = true;
      this.isScrollShow = true;
      this.isSlotShow = false;
      this.isDevise = true;
    }else if(e.detail.value == "50"){
      this.isPrintShow = true;
      this.isCardShow = true;
      this.isScrollShow = true;
      this.isSlotShow = true;
      this.isDevise = false;
    };
    //重新赋值
    this.setData({
      items,
      [`formData.business`]: e.detail.value,
      isPrintShow:this.isPrintShow,
      isCardShow:this.isCardShow,
      isScrollShow:this.isScrollShow,
      isSlotShow:this.isSlotShow,
      isDevise:this.isDevise,
    })
  },
  //颜色radio调用方法
  radioChangeColorList: function (e) {
    const items = this.data.colorList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.color`]: e.detail.value
    })
  },
  //尺寸radio调用方法
  radioChangeSizeList: function (e) {
    const items = this.data.sizeList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.size`]: e.detail.value
    })
  },
  //打印类型radio调用方法
  radioChangePrintTypeList: function (e) {
    const items = this.data.printTypeList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.printType`]: e.detail.value
    })
  },
  //纸张类型radio调用方法
  radioChangePrintPaperTypeList: function (e) {
    const items = this.data.printPaperTypeList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.printPaperType`]: e.detail.value
    })
  },
  //装订方式radio调用方法
  radioChangeBindTypeList: function (e) {
    const items = this.data.bindTypeList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.bindType`]: e.detail.value
    })
  },
  //名片制作纸张类型radio调用方法
  radioChangeCardPaperTypeList: function (e) {
    const items = this.data.cardPaperTypeList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.cardPaperType`]: e.detail.value
    })
  },
  //条幅制作颜色radio调用方法
  radioChangeBannerColorList: function (e) {
    const items = this.data.bannerColorList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.bannerColor`]: e.detail.value
    })
  },
  //线上设计类型radio调用方法
  radioChangeDesignTypeList: function (e) {
    const items = this.data.designTypeList
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    //重新赋值
    this.setData({
      items,
      [`formData.designType`]: e.detail.value
    })
  },
  //期望时间
  bindDateChange(e) {
    this.setData({
      time: e.detail.value,
      'formData.time': e.detail.value
    })
  },
  //所有input框输入
  formInputChange(e) {
    const { field } = e.currentTarget.dataset
    this.setData({
      [`formData.${field}`]: e.detail.value
    })
  },
  submitForm() {
    console.log(this.data.formData)
    this.selectComponent('#form').validate((valid, errors) => {
      console.log('valid', valid, errors)
      if (!valid) {
        const firstError = Object.keys(errors)
        if (firstError.length) {
          this.setData({
            error: errors[firstError[0]].message
          })
        }
      } else {
        wx.showToast({
          title: '校验通过'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})